package io.sdph.products;

import io.sdph.products.model.Product;
import io.sdph.products.dao.MagazineManagerDAO;
import io.sdph.products.dao.MagazineManagerDB;

import javax.ejb.Stateless;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Manager zarządzający stanem magazynu.
 * 
 * @author 
 * @since 0.0.1
 */
@Service
public class MagazineManager implements IMagazineManager {

	@Autowired
	MagazineManagerDAO managerDAO;
	
	@Override
	public void addProduct(Product product, long quantity) {
		
		managerDAO.addQuantity(product, quantity);
		
	}

	@Override
	public void removeProduct(Product product, long quantity) {
				
		long ilosc;
		ilosc= managerDAO.getQuantity(product);
		ilosc=ilosc-quantity;
		managerDAO.setQuantity(product, ilosc);
		
	}

	@Override
	public void setQuantityOfProduct(Product product, long quantity) {

		managerDAO.setQuantity(product, quantity);
		
	}

	@Override
	public long getQuantityOfProduct(Product product) {

		Long ilosc;
		ilosc=managerDAO.getQuantity(product);
		
		return ilosc==null?0:ilosc;
	}

}
